<?php

namespace App\Http\Middleware;

use App\Blocks\User;
use App\Libs\Message;
use Closure;

class Auth {

    public function handle($request , Closure $next , $gurad = null){

        $sessionKey = $request->get('token');

        global $g_uid;

        if($sessionKey === 'test'){
            $userBlock = new User();
            $userData = $userBlock->getActivityUserInfoByUid(19);
        }else {
            $userData = \Cache::get($sessionKey);
        }

        if(!isset($userData->id) || $userData->id <= 0){
            return response()->json(Message::setResponseInfo('NO_LOGIN'));
        }

        $g_uid = $userData->id;
        return $next($request);
    }
}